/*
 * @lc app=leetcode.cn id=128 lang=javascript
 *
 * [128] 最长连续序列
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var longestConsecutive = function (nums) {
    const set = new Set(nums)
    let max = 0
    for (let i = 0; i < nums.length; i++) {
        if (!set.has(nums[i] - 1)) {
            let count = 1
            let curr = nums[i]
            while (set.has(curr+ 1)) {
                count++
                curr++
            }
            max = Math.max(count, max)
        }
    }
    return max
};
// @lc code=end

